
local Entity = require'entities.entity'

local Part = {}
Part.mt = { __index = Part }
setmetatable(Part, Entity.mt)

function Part.initialize(deck, slot, x, y, transform, layer)
	if not deck then 
	local msg = "ERROR: improper deck for part"; 
	print(msg); return msg end
	
	local pizzard = {}
	setmetatable(pizzard, Entity.mt)	
	
	local part_type = 'part'
	if deck ~= 'hook_tile' then
		pizzard = Entity.new(part_type, deck, x, y)
		setmetatable(pizzard, Part.mt)
		pizzard.prop:setPriority(50)
	elseif deck == 'hook_tile' then
		
		pizzard.origin_x = x
		pizzard.origin_y = y
		pizzard.name = deck
		pizzard.type = part_type
		pizzard.prop = MOAITransform2D.new()
		
		pizzard.prop:setLoc(x, y)
		
		EntityManager:add_entity( pizzard )
	end
	
	
	
	if transform then 
		--if not self.parent then self.parent = {} end
		--rawset(self, parent, transform); 
		Entity.setParent(pizzard, transform, 't');
	end
	
	
	
	pizzard.name = deck
	pizzard.slot = slot
	pizzard.health = 100
	pizzard.dmg_rate = 0.75
	if deck ~= 'hook_tile' then
		layer:insertProp(pizzard.prop)
	end
	
	
	return pizzard

end


function Part.new(deck, slot, x, y, transform, layer)
	--print("part ", x, y)
	local o = Part.initialize(deck, slot, x, y, transform, layer)

	return o

end



return Part